﻿using QFramework.RollABall;
using UnityEngine;

namespace QFramework.Example
{
    public class RollABall : MonoBehaviour
    {
        private void Awake()
        {
            Setup();
            BindInput();
        }


        /// <summary>
        /// 游戏区域（场景设置）
        /// </summary>
        private GameArea mGameArea { get; set; }

        /// <summary>
        /// 游戏摄像机
        /// </summary>
        private GameCamera mGameCamera { get; set; }

        /// <summary>
        /// 可拾取块管理器
        /// </summary>
        private PickUpManager mPickUpManager { get; set; }


        /// <summary>
        /// 玩家（球）
        /// </summary>
        private Player mPlayer { get; set; }

        /// <summary>
        /// 游戏信息显示
        /// </summary>
        private GameUI mGameUI { get; set; }

        /// <summary>
        /// 拾取的数量
        /// </summary>
        private int PickUpCount = 0;

        /// <summary>
        /// 设置
        /// </summary>
        void Setup()
        {
            // 创建 GameArea
            mGameArea = new GameArea();

            mGameCamera = new GameCamera();

            mPickUpManager = new PickUpManager();

            mPlayer = new Player();

            mGameUI = new GameUI();
        }

        /// <summary>
        /// 绑定并处理输入
        /// </summary>
        void BindInput()
        {
            mPlayer.StartListenUserInput();

            mPlayer.StartCheckCollision(OnPickUp);

            mGameCamera.StartFollowPlayer(mPlayer.GameObject);
        }

        void OnPickUp()
        {
            PickUpCount++;

            if (PickUpCount >= 12)
            {
                mGameUI.ShowGameSucceedText();
            }
            else
            {
                mGameUI.UpdatePickUpCountText(PickUpCount);
            }
        }
    }
}